//
//  StepValidExerciseView.swift
//  MoyoungHome
//
//  Created by 李然 on 2022/9/17.
//

import UIKit
import MYModule

class ActivityValidExerciseView: View {

	var curWeekValidTime: Int = 0 {
		didSet {
            let timeStr = curWeekValidTime == 0 ? "--" : "\(curWeekValidTime)"
            let content = "activity_week_volume_description".language(with: [timeStr])
			self.weekLabel.attributedText = content.toAttributed
				.foregroundColor(UIColor.assist_000000)
				.font(Fonts.systemFont(ofSize: 12))
				.font(Fonts.systemFont(ofSize: 20), range: (content as NSString).range(of: timeStr))
				.rawValue
		}
	}

	override func makeUI() {
		super.makeUI()

		self.backgroundColor = UIColor.background

		addSubview(titleLabel)
		titleLabel.snp.makeConstraints { make in
			make.leading.top.equalTo(26)
			make.trailing.lessThanOrEqualTo(-10)
		}

		addSubview(weekLabel)
		weekLabel.snp.makeConstraints { make in
			make.leading.equalTo(26)
            make.top.equalTo(titleLabel.snp.bottom).offset(22)
		}

		addSubview(recommendLabel)
		recommendLabel.snp.makeConstraints { make in
			make.leading.equalTo(26)
            make.top.equalTo(weekLabel.snp.bottom).offset(10)
		}
        
        let boxView = UIView()
        boxView.backgroundColor = UIColor.background
        addSubview(boxView)
        boxView.snp.makeConstraints { make in
            make.top.equalTo(recommendLabel.snp.bottom).offset(25)
            make.centerX.equalToSuperview()
        }
        
        boxView.addSubview(dataLabel)
        dataLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.leading.top.bottom.equalToSuperview()
        }
        boxView.addSubview(unitLabel)
        unitLabel.snp.makeConstraints { make in
            make.trailing.equalToSuperview()
            make.bottom.equalTo(-8)
            make.leading.equalTo(dataLabel.snp.trailing).offset(3)
        }

        addSubview(explainView)
		addSubview(chartView)
		chartView.snp.makeConstraints { make in
            make.top.equalTo(boxView.snp.bottom).offset(15)
			make.height.equalTo(120)
			make.leading.equalTo(6)
			make.trailing.equalTo(-6)
		}

		explainView.snp.makeConstraints { make in
            make.top.equalTo(chartView.snp.bottom).offset(15)
			make.leading.trailing.bottom.equalToSuperview()
		}
	}
    
    //MARK: - lazy load
    lazy var titleLabel: Label = {
        let label = Label()
        label.font = Fonts.boldSystemFont(ofSize: 14)
        label.textColor = UIColor.assist_222222
        label.numberOfLines = 0
        label.text = "activity_volume_upper_title".language
        return label
    }()

    lazy var dataLabel: Label = {
        let label = Label()
        label.text = "--"
        label.font = Fonts.systemFont(ofSize: 44)
        label.textColor = UIColor.assist_222222
        return label
    }()

    lazy var unitLabel: Label = {
        let label = Label()
        label.font = Fonts.systemFont(ofSize: 12)
        label.textColor = UIColor.assist_222222
        label.text = "unit_steps_effective_activity".language
        return label
    }()

    lazy var weekLabel: Label = {
        let label = Label()
        return label
    }()

    lazy var recommendLabel: Label = {
        let label = Label()
        label.font = Fonts.systemFont(ofSize: 12)
        label.textColor = UIColor.assist_A9A9A9
        label.text = "activity_week_recommend_volume_description".language
        return label
    }()

    lazy var chartView: DFBarChartView = {
        let view = DFBarChartView()
        return view
    }()

    lazy var explainView: ExPlainView = {
        let view = ExPlainView()
        view.backgroundColor = UIColor.background
        view.updateData(
            textColor: UIColor.Step.theme,
            title: "activity_volume_title".language,
            explain: "activity_volume_description".language,
            explainTextColor:UIColor.Step.theme.withAlphaComponent(0.8),
            bgColor: UIColor.Step.theme)
        return view
    }()

}
